# -*- coding: utf-8 -*-
# @File: backend => transactions.py
# @CreateTime: 2025/8/25 21:39
# @Author: EvanZhang
# @Info: 金币流水，充值、买入、赢钱、税收

from tortoise import fields, models

# id | user_id | delta | type | ref_hand_id | created_at
class Transaction(models.Model):
    id = fields.IntField(pk=True)
    user = fields.ForeignKeyField("models.User", related_name="transactions", description="所属用户")
    delta = fields.IntField(description="金币变动数，正数为增加，负数为减少")
    type = fields.CharField(max_length=20, description="交易类型，如'recharge', 'buy_in', 'win', 'tax'")
    ref_hand = fields.ForeignKeyField('models.Hand', related_name="transactions", null=True, description="关联的牌局（如有）")
    created_at = fields.DatetimeField(auto_now_add=True, description="交易时间")

    class Meta:
        table = "transactions"
        description = "金币流水表"
        index_together = (("user", "type"),)
